<?php
 $host = 'localhost';
 $user = 'root';
 $pass = '';
 $db = 'gomsu';
 $table = 'sanpham';
 $file = 'export';
 
 $link = mysql_connect($host, $user, $pass) or die("Can not1 connect." . mysql_error());
 mysql_select_db($db) or die("Can not2 connect.");
 
 $result = mysql_query("SHOW COLUMNS FROM ".$table."");
 $i = 0;
 if (mysql_num_rows($result) >
0) {
 $csv_output='';
 while ($row = mysql_fetch_assoc($result)) {
 $csv_output.= $row['Field'].", ";
 $i++;
 }
 }
 $csv_output.= "\n";
 
 $values = mysql_query("SELECT * FROM ".$table."");
 while ($rowr = mysql_fetch_row($values)) {
 for ($j=0;$j
<$i;$j++) {
 $csv_output .= $rowr[$j].", ";
 }
 $csv_output .= "\n";
 }
 
 $filename = $file."_".date("YmdHis_",time());
 header("Content-type: application/vnd.ms-excel");
 header("Content-disposition: csv" . date("Y-m-d") . ".csv");
 header( "Content-disposition: filename=".$filename.".csv");
 print $csv_output;
 exit;
 ?>
	<?php
/*
include_once("../DataProvider.php");
$sql="select * into outfile 'D:/sanpham.csv' FIELDS TERMINATED BY ',' ENCLOSED BY ''  LINES TERMINATED BY '\n' from sanpham;";
$kq=DataProvider::ExecuteQuery($sql);
if($kq)
	echo "<head>
	<meta http-equiv='refresh' content='0;URL= index.php'></head>
	";
else
	echo "That Bai";
	*/
?>